﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
@section Content {
    <link href="~/Areas/WeChat/Shared/iconfont.css" rel="stylesheet" />
}
<script>
    var settings = [];
    $(function () {
        $.ajax({
            url: "/Wechat/Setting/GetKeyValueJson",
            data: {},
            dataType: "json",
            async: false,
            success: function (data) {
                //console.log(data);
                settings = (data);
                initControl();
                gridList();
            }
        });
    })
    function initControl() {
        var html = '';
        for (var i = 0; i < settings.length; i++) {
            html += '<option value="' + settings[i].Value + '">' + settings[i].Text + '</option>';
        }
        //$("#txt_type").append(html).select2({
        //    placeholder: '没有菜单',
        //    width: '100%' // need to override the changed default
        //});
        $("#txt_type").append(html).bindSelect();
    }

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/WeChat/SettingItems/GetGridJson",
            height: $(window).height() - 126,
            colModel: [
                { label: '编号', name: 'F_Id', hidden: true },
                {
                    label: '首页项', name: 'F_SettingId', width: 150, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        var result = '';
                        if (settings.length) {
                            for (var i = 0; i < settings.length; i++) {
                                if (cellvalue == settings[i].Value) {
                                    result = settings[i].Text;
                                    break;
                                }
                            }
                        }
                        return result;
                    }
                },
                {
                    label: '图标', name: 'F_Icon', width: 50, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue ? '<span class="iconfont ' + cellvalue + '" style="font-size: 32px"></span>' : '';
                    }
                    
                },
                {
                    label: '图片地址', name: 'F_ImageSrc', width: 100, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue ? '<img src="' + cellvalue + '" alt="示例图" style="wdith: 140px;height:140px;" />' : '';
                    }
                },
                { label: '标题', name: 'F_Title', width: 200, align: 'left' },
                { label: '主题内容', name: 'F_Subject', width: 250, align: 'left' },
                { label: '跳转地址编号', name: 'F_LinkId', width: 250, align: 'left' },
                {
                    label: '状态', name: 'F_State', width: 100, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue ? '启用' : '禁用';
                    }
                },
                { label: '排序', name: 'F_Sort', width: 100, align: 'left' }
            ],
            pager: "#gridPager",
            sortname: 'F_Id asc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify({ keyword: $("#txt_keyword").val(), type: $("#txt_type").val()  })},
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增菜单项",
            url: "/WeChat/SettingItems/Form",
            width: "1000px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Form",
            title: "修改菜单项",
            url: "/WeChat/SettingItems/Form?keyValue=" + keyValue,
            width: "1000px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        $.deleteForm({
            url: "/WeChat/SettingItems/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().F_Id },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }
</script>

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>添加</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a></li>
                <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
        <script>$('.toolbar').authorizeButton()</script>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group" style="padding: 0 10px;">
                        <select id="txt_type" class="select2 form-control">
                        </select>
                    </div>
                </td>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>

<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>


